# -*- coding: utf-8 -*-
# @File: backend => room_players.py
# @CreateTime: 2025/8/25 14:25
# @Author: EvanZhang
# @Info: 玩家与房间的绑定历史，用于战绩统计

from tortoise import fields, models

# id | room_id | user_id | seat_index | buy_in_chips | left_chips | created_at | left_at
class RoomPlayer(models.Model):
    id = fields.IntField(pk=True)
    room = fields.ForeignKeyField('models.Room', related_name="players", description="所属房间")
    user = fields.ForeignKeyField("models.User", related_name="room_players", description="所属用户")
    seat_index = fields.IntField(description="座位索引", null=True)  # 玩家在房间中的座位索引，null表示已离开，未分配座位
    buy_in_chips = fields.IntField(description="买入筹码")
    left_chips = fields.IntField(description="剩余筹码")
    created_at = fields.DatetimeField(auto_now_add=True, description="加入时间")
    left_at = fields.DatetimeField(null=True, description="离开时间")

    class Meta:
        table = "room_players"
        description = "房间玩家表"
        unique_together = (("room", "user"), ("room", "seat_index"))